package cn.kgc.takemanager01.service.impl;

import cn.kgc.takemanager01.mapper.TakeoutMapper;
import cn.kgc.takemanager01.pojo.Takeout;
import cn.kgc.takemanager01.pojo.TakeoutExample;
import cn.kgc.takemanager01.service.TakeoutService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 * @create 郭祥伟
 */
@Service
public class TakeoutServiceImpl implements TakeoutService {
    @Resource
    TakeoutMapper takeoutMapper;

    @Override
    public PageInfo<Takeout> select(Integer pageNum, Integer pageSize, Integer productId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Takeout> takeoutList;
        if(productId!=0){
            TakeoutExample example=new TakeoutExample();
            TakeoutExample.Criteria criteria=example.createCriteria();
            criteria.andProductidEqualTo(productId);
            takeoutList=takeoutMapper.selectByExample(example);
        }else{
            takeoutList=takeoutMapper.selectByExample(null);
        }
        PageInfo<Takeout> pageInfo=new PageInfo<>(takeoutList);
        return pageInfo;
    }

    @Override
    public Integer add(Takeout takeout) {
        int i=takeoutMapper.insert(takeout);
        return i;
    }

    @Override
    public Takeout selectById(Integer id) {
        Takeout takeout=takeoutMapper.selectByPrimaryKey(id);
        return takeout;
    }

    @Override
    public Integer update(Takeout takeout) {
        int i=takeoutMapper.updateByPrimaryKey(takeout);
        return i;
    }

    @Override
    public Integer delete(Integer id) {
        int i=takeoutMapper.deleteByPrimaryKey(id);
        return i;
    }
}
